package week3;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

/**
 * @author The Setting sun
 * @create 2021-09-23 14:21
 */
public class work1 {
    public static void main(String[] args) {
        JFrame frame = new JFrame();

//        JPanel panel = new JPanel();
        JLabel label = new JLabel("坐标");
        label.setFont(new Font("微软雅黑", Font.BOLD, 18));

        JTextArea area = new JTextArea();
        area.setFont(new Font("微软雅黑", Font.BOLD, 18));
        JScrollPane scroll = new JScrollPane(area);

        area.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getButton() == MouseEvent.BUTTON1){
                    area.append("鼠标左键" + e.getX() + "，" + e.getY() + "\n");
                }
                if (e.getButton() == MouseEvent.BUTTON2){
                    area.append("鼠标中键" + e.getX() + "，" + e.getY() + "\n");
                }
                if (e.getButton() == MouseEvent.BUTTON3){
                    area.append("鼠标右键" + e.getX() + "，" + e.getY() + "\n");
                }
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                area.append("我进来了" + "\n");
            }

            @Override
            public void mouseExited(MouseEvent e) {
                area.append("我出去了" + "\n");
            }
        });

        label.addMouseMotionListener(new MouseMotionAdapter() {
            @Override
            public void mouseMoved(MouseEvent e) {
                label.setText("坐标：" + e.getX() + "，" + e.getY());
            }
        });

//        panel.add(label);
        frame.add(scroll, BorderLayout.CENTER);
        frame.add(label, BorderLayout.NORTH);

        frame.setLocationRelativeTo(null);
        frame.setSize(600, 500);
        frame.setVisible(true);
    }
}
